import axios from 'axios'
const service = axios.create({
  //baseURL: "http://localhost", // url = base url + request url
  timeout: 5000, // request timeout
})

service.interceptors.request.use(
  config => {
    // if (store.getters.token) {
    //   config.headers['X-Token'] = getToken()
    // }
    return config
  },
  error => {
    console.log(error) // for debug
    return Promise.reject(error)
  },
)

service.interceptors.response.use(
  response => {
    const res = response.data
    console.log(res)
    if (response.status != 200) {
      console.log('接口信息报错', response.statusText)
      return Promise.reject(new Error(response.statusText || 'Error'))
    } else {
      return res
    }
  },
  error => {
    console.log('接口信息报错' + error)
    return Promise.reject(error)
  },
)

export default service
